/**
 * Created by kangdaye on 16/6/5.
 */
app.controller('employeeListCtr',["$scope","$rootScope","ngDialog","confirm","message","employeeCache","employeeService", function($scope,$rootScope,ngDialog,confirm,message,employeeCache,employeeService) {
    $scope.getData = {
        query : ''
    };
    $scope.gridOptions = {
        url          : servicePath + 'employee/list',
        columnDefs   : employeeCache.listTableHeader,
        params       : $scope.getData,
        selectAll    : true
    };

    $scope.searchClick = function(){
        $scope.gridOptions.search();
    };
    
    $scope.addEdit = function(model){
        ngDialog.open({
            template: '/admin/view/order/employee/employeeAEDialog.html',
            width: 480,
            controller: 'employeeAEDialogCtr',
            resolve: {
                gridOpt : function(){
                    return $scope.gridOptions
                },
                addEditModel: function(){
                    return model
                }
            }
        });
    };

    $scope.delete = function(id){
        confirm({
            text:'确定要删除吗？',
            option:{
                go:function(){
                    var selectIds = angular.add($scope.gridOptions.selectData,'id');
                    employeeService.delete({
                        ids : id || selectIds.toString()
                    },function(){
                        $scope.gridOptions.refresh();
                        message({text : '删除成功'});
                    });
                }
            }
        });
    };
    $scope.isBindMan = function(id){
        ngDialog.open({
            template: '/admin/view/order/employee/employeeBindDialog.html',
            width: 400,
            controller: 'employeeBindCtr',
            resolve: {
                getData: function() {
                    return {
                        employeeId : id
                    };
                }
            }
        });
    };

}]);
/**
 * Created by wk on 16/9/16.
 */
app.controller('employeeBindCtr',["$scope","$rootScope","ngDialog","$http","getData","distrVipService", function($scope,$rootScope,ngDialog,$http,getData,distrVipService) {
    $scope.memberId = "";
    $scope.getData = getData;

    $scope.submit = function(){
       $http({
            method:'POST',
            url: servicePath +'member/employeebinding_member',
            cache: false,
            dataType: 'json',
            data:{
                employeeId:parseFloat(getData.employeeId),
                memberId:parseFloat($scope.memberId)
            }
        }).success(function(data, status) {
            if(status==200){
             ngDialog.closeAll();   
            }
        })
    };
    $scope.cancel = function(){
        ngDialog.closeAll();    
    };
}]);